﻿/*
 * Created by SharpDevelop.
 * User: rogerio
 * Date: 5/2/2010
 * Time: 8:42
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;

namespace csharp.rad.finan.researchs
{
	/// <summary>
	/// Description of frmResearchPurchase.
	/// </summary>
	public partial class frmResearchPurchase : csharp.common.SearchTemplate
	{
		general.Purchases listPurchases = new csharp.rad.general.Purchases();
		
		public frmResearchPurchase()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		#region overridede method's
		protected override void init()
		{
			KryptonDataGridViewTextBoxColumn purchase_number = new KryptonDataGridViewTextBoxColumn();
			KryptonDataGridViewTextBoxColumn doc_number = new KryptonDataGridViewTextBoxColumn();
			KryptonDataGridViewTextBoxColumn emission_date = new KryptonDataGridViewTextBoxColumn();
			KryptonDataGridViewTextBoxColumn valuer = new KryptonDataGridViewTextBoxColumn();
			
			purchase_number.Name = "purchase_number";
			purchase_number.HeaderText = "Nº Compra";
			purchase_number.Width = 80;
			
			doc_number.Name = "doc_number";
			doc_number.HeaderText = "Nº Doc.";
			doc_number.Width = 80;
			
			emission_date.Name = "emission_date";
			emission_date.HeaderText = "Data Emissão";
			emission_date.Width = 100;
			
			valuer.Name = "value";
			valuer.HeaderText = "Valor";
			valuer.Width = 80;
			
			dgvMain.Columns.AddRange(new DataGridViewColumn[] {purchase_number, doc_number, emission_date, valuer});
			
			clearFields();
		}
		
		protected override void fillDataGridView()
		{
			int tam = listPurchases.count();
			
			dgvMain.Rows.Clear();
			for(int i=0; i < tam; i++)
				dgvMain.Rows.Add(new String[] {listPurchases.get(i).id,
				                 	listPurchases.get(i).Number_purchase,
				                 	listPurchases.get(i).Document,
				                 	listPurchases.get(i).Date_emissao,
				                 	listPurchases.get(i).General_total});
		}
		
		protected override void edit()
		{
			KryptonMessageBox.Show("Método não implementado!","Atenção");
			//finan.views.frmPurchase form = new finan.views.frmPurchase();
			
			//form.ShowDialog();
		}
		#endregion
		
		private void BtnSearchClick(object sender, EventArgs e)
		{
			search();
		}
		
		private void search()
		{
			if(listPurchases.fillList(txtNumberPurchase.Text,
			                          txtDocument.Text, 
			                          dtpDateEmissaoInit.Text, 
			                          dtpDateEmissaoEnd.Text))
			{
				fillDataGridView();
			}
		}
		
		private void clearFields()
		{
			txtDocument.Text = string.Empty;
			txtNumberPurchase.Text = string.Empty;
			
			dtpDateEmissaoInit.Value = Convert.ToDateTime(common.Util.primeiroDiaMes(DateTime.Now.Month, DateTime.Now.Year));
			dtpDateEmissaoEnd.Value = DateTime.Now;
		}
	}
}
